package com.ruoyi.web.controller.student_club.admin_controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.student_club.domain.FirstMessage;
import com.ruoyi.student_club.service.IFirstMessageService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 留言管理Controller
 * 
 * @author 无尤
 * @date 2022-01-14
 */
@Controller
@RequestMapping("/firstMessage/message")
public class FirstMessageController extends BaseController
{
    private String prefix = "firstMessage/message";

    @Autowired
    private IFirstMessageService firstMessageService;

    @RequiresPermissions("firstMessage:message:view")
    @GetMapping()
    public String message()
    {
        return prefix + "/message";
    }

    /**
     * 查询留言管理列表
     */
    @RequiresPermissions("firstMessage:message:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FirstMessage firstMessage)
    {
        startPage();
        List<FirstMessage> list = firstMessageService.selectFirstMessageList(firstMessage);
        return getDataTable(list);
    }

    /**
     * 导出留言管理列表
     */
    @RequiresPermissions("firstMessage:message:export")
    @Log(title = "留言管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FirstMessage firstMessage)
    {
        List<FirstMessage> list = firstMessageService.selectFirstMessageList(firstMessage);
        ExcelUtil<FirstMessage> util = new ExcelUtil<FirstMessage>(FirstMessage.class);
        return util.exportExcel(list, "留言管理数据");
    }

    /**
     * 新增留言管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存留言管理
     */
    @RequiresPermissions("firstMessage:message:add")
    @Log(title = "留言管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FirstMessage firstMessage)
    {
        return toAjax(firstMessageService.insertFirstMessage(firstMessage));
    }

    /**
     * 修改留言管理
     */
    @RequiresPermissions("firstMessage:message:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        FirstMessage firstMessage = firstMessageService.selectFirstMessageById(id);
        mmap.put("firstMessage", firstMessage);
        return prefix + "/edit";
    }

    /**
     * 修改保存留言管理
     */
    @RequiresPermissions("firstMessage:message:edit")
    @Log(title = "留言管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FirstMessage firstMessage)
    {
        return toAjax(firstMessageService.updateFirstMessage(firstMessage));
    }

    /**
     * 删除留言管理
     */
    @RequiresPermissions("firstMessage:message:remove")
    @Log(title = "留言管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(firstMessageService.deleteFirstMessageByIds(ids));
    }
}
